import pandas
from tkinter import messagebox
from Model import *
from View import *
from Control.copyctrl import *
from Control.matchctrl import *
from Control.cleanctrl import *

def readexcel0():
    if len(excelChooser.filenames) > 0:
        return excelChooser.selected()[excelChooser.filenames[0]]
    else:
        return "None"
    pass

def showinputError():
    messagebox.showinfo("文件地址无效",
                           "请选择需要处理的EXCEL文件！")
    startmenu.ws.focus_force()
    print("录入地址无效！")

def gotoCopyMenu():
    print(readexcel0())
    if readexcel0() != "None":
        excel0.inputexcel(readexcel0())
        excelCopyResult.createexcel(df=excel0.df)
        copyIndexChooser.resetmenu("请选择索引列", excelCopyResult.cindex)
        toCopyIndexChooser.resetmenu("抄写哪一列？",list())
        copyPreviewTable.loaddata(excelCopyResult.df)
        print("跳转至抄写数据")
        RF.reshowworkingspace("抄写数据")
    else:
        showinputError()


def gotoMatchMenu():
    print(readexcel0())
    if readexcel0() != "None":
        excel0.inputexcel(readexcel0())
        excelMatchResult.createexcel(df=excel0.df)
        matchIndexChooser.resetmenu("请选择索引列", excelMatchResult.cindex)
        matchPreviewTable.loaddata(excelMatchResult.df)
        print("跳转至抄写数据")
        RF.reshowworkingspace("对比数据")
    else:
        showinputError()

def gotoCleanMenu():
    print(readexcel0())
    if readexcel0() != "None":
        excel0.inputexcel(readexcel0())
        excelCleanResult.createexcel(df=excel0.df)
        cleanPreviewTable.loaddata(excelCleanResult.df)
        print("跳转至删除空行")
        RF.reshowworkingspace("删除空行")
    else:
        showinputError()


toCopyButton.configure(command=gotoCopyMenu)
toMatchButton.configure(command=gotoMatchMenu)
toCleanButton.configure(command=gotoCleanMenu)

